import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/ext.dart';
import 'package:enterprise_v6_app/app/data/entities/application/Inventory_system/risk_management_list_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/inventory_system/risk_control_checklist/risk_control_checklist_controller.dart';

///风险管控清单
class RiskControlChecklistPage extends StatelessWidget {
  RiskControlChecklistPage({super.key}){
    Get.lazyPut(RiskControlChecklistController.new);
  }
  @override
  Widget build(BuildContext context) {
    final RiskControlChecklistController controller = Get.find<RiskControlChecklistController>();
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            key: controller.riskRightScaffoldKey,
            body: Container(
              color: AppColors.bg_color_grey,
              padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
              child: Column(
                children: [
                  Row(
                    children: [
                      Expanded(
                        child: _getSearchEnterWidget(controller),
                      ),
                      AppGaps.hGap8,
                      _screen(controller),
                      AppGaps.vGap10,
                    ],
                  ),
                  AppGaps.vGap12,
                  Expanded(
                      child: CustomEasyRefreshList<RiskManagementListEntity>(
                    key: controller.globalKey,
                    dataLoad: controller.riskManagementList,
                    itemBuilder: (item, index) {
                      return _itemWidget(item,controller);
                    },
                  ))
                ],
              ),
            ),
            // endDrawer: CustomEndDrawer(
            //   centerContext: Column(
            //     children: [
            //       _selectType(
            //         '清单内容',
            //         input: Container(
            //             height: 38.w,
            //             padding: EdgeInsets.symmetric(horizontal: 12.w),
            //             alignment: Alignment.center,
            //             decoration: BoxDecoration(
            //                 color: Colors.white,
            //                 border: Border.all(color: const Color(0xffF0F0F0), width: 1.w),
            //                 borderRadius: BorderRadius.all(Radius.circular(8.w))),
            //             child: Row(
            //               children: [
            //                 Expanded(
            //                     child: Obx(() => TextField(
            //                         keyboardType: TextInputType.text,
            //                         textInputAction: TextInputAction.done,
            //                         controller:
            //                             TextEditingController(text: controller.searchX.value.isNotEmpty ? controller.searchX.value : controller.searchSelect),
            //                         onChanged: (value) {
            //                           controller.searchSelect = value;
            //                         },
            //                         style: TextStyle(color: const Color(0xff222222), fontWeight: FontWeight.w400, fontSize: 14.sp),
            //                         decoration: InputDecoration(
            //                           counterText: '',
            //                           //防止适配不居中
            //                           isCollapsed: true,
            //                           border: const OutlineInputBorder(borderSide: BorderSide.none),
            //                           contentPadding: EdgeInsets.only(left: 8.w),
            //                           hintText: '请输入搜索内容',
            //                           hintStyle: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
            //                         ))))
            //               ],
            //             )),
            //           controller,
            //       ),
            //       _selectType('风险等级',controller),
            //       RegionalOrganizationTreePage(
            //         selectedEntity: controller.selectedEntity,
            //         onCallBack: (RiskTreeEntity entity) {
            //           controller.selectedEntity = entity;
            //         },
            //       ),
            //     ],
            //   ),
            //   reset: controller.reset,
            //   confirm: controller.confirm,
            // ),
          );
        });
  }

  //搜索框
  Widget _getSearchEnterWidget(RiskControlChecklistController controller) {
    return Container(
        height: 38.w,
        padding: EdgeInsets.symmetric(horizontal: 12.w),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: Colors.white, border: Border.all(color: const Color(0xffF0F0F0), width: 1.w), borderRadius: BorderRadius.all(Radius.circular(8.w))),
        child: Row(
          children: [
            SvgPicture.asset(
              AppImages.icon_search,
              width: 16.w,
            ),
            Expanded(
                child: TextField(
                    keyboardType: TextInputType.text,
                    textInputAction: TextInputAction.done,
                    controller: TextEditingController(text: controller.searchX.value),
                    onChanged: (value) {
                      controller.searchX.value = value;
                      controller.refreshPage();
                    },
                    style: TextStyle(color: const Color(0xff222222), fontWeight: FontWeight.w400, fontSize: 14.sp),
                    decoration: InputDecoration(
                      counterText: '',
                      //防止适配不居中
                      isCollapsed: true,
                      border: const OutlineInputBorder(borderSide: BorderSide.none),
                      contentPadding: EdgeInsets.only(left: 8.w),
                      hintText: '请输入搜索内容',
                      hintStyle: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
                    )))
          ],
        ));
  }

  ///筛选
  Widget _screen(RiskControlChecklistController controller) {
    return Container(
      width: 38.w,
      height: 38.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        AppImages.icon_search_screen,
        width: 16.w,
      ),
    ).click(controller.onFilterButtonPressed);
  }


  Widget _itemWidget(RiskManagementListEntity item, RiskControlChecklistController controller) {
    return CustomTitleChartPage(
        title: item.riskName ?? '',
        child: Column(
          children: [
            Row(
              children: [
                Text(
                  '安全风险管控名称：',
                  style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, color: const Color(0xffA5A6B5)),
                ),
                Expanded(
                  child: Align(
                    alignment: Alignment.topRight,
                    child: Text(
                      item.riskName ?? '',
                      style: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w400, color: const Color(0xff495061)),
                    ),
                  ),
                ),
              ],
            ),
            Row(
              children: [
                Text(
                  '伤害类型：',
                  style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, color: const Color(0xffA5A6B5)),
                ),
                Expanded(
                  child: Align(
                    alignment: Alignment.topRight,
                    child: Text(
                      item.damageType ?? '',
                      style: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w400, color: const Color(0xff495061)),
                    ),
                  ),
                ),
              ],
            ),
            AppGaps.vGap10,
            Row(
              children: [
                Text(
                  '管控措施：',
                  style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, color: const Color(0xffA5A6B5)),
                ),
                Expanded(
                  child: Align(
                    alignment: Alignment.topRight,
                    child: Text(
                      item.controlMeasures ?? '',
                      style: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w400, color: const Color(0xff495061)),
                    ),
                  ),
                ),
              ],
            ),
            AppGaps.vGap10,
            Row(
              children: [
                Text(
                  '详情：',
                  style: TextStyle(fontSize: 13.sp, fontWeight: FontWeight.w400, color: const Color(0xffA5A6B5)),
                ),
                const Spacer(),
                Container(
                  padding: EdgeInsets.only(left: 10.w, right: 2.w, top: 2.w, bottom: 2.w),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5),
                    color: const Color(0xFF5C6DFF).withOpacity(0.1),
                  ),
                  child: Row(
                    children: [
                      Text(
                        '管控情况',
                        style: TextStyle(
                          color: const Color(0xFF5C6DFF),
                          fontSize: 12.sp,
                          fontWeight: FontWeight.w400,
                        ),
                      ),
                      // Icon(
                      //   Icons.arrow_right,
                      //   color: Color(0xFF5C6DFF),
                      // )
                      SvgPicture.asset(
                        AppImages.icon_right_arrow,
                      ),
                      AppGaps.hGap2,
                    ],
                  ).clickOnce(() {
                    controller.controlSituation(item);
                  }),
                )
              ],
            ),
          ],
        ));
  }

}
